package com.hnkywl.sts.dao.jhgl;

import com.hnkywl.sts.entity.jhgl.Zgwzjh;
import net.ruixin.orm.hibernate.Page;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.Criteria;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: ZHUCHG
 * Date: 13-4-3
 * Time: 上午10:01
 * To change this template use File | Settings | File Templates.
 */
@Repository
public class ZgwzjhDao extends WzjhDao<Zgwzjh> {
    public Page<Zgwzjh> findZgwzjh(Long ssgsId, String spzt, boolean forZjjh, int pageNo, int pageSize) {
        Page<Zgwzjh> page = new Page<Zgwzjh>();
        page.setPageNo(pageNo);
        page.setPageSize(pageSize);
        page.setAutoCount(true);
        List<Object> param = new ArrayList<Object>();
        List<String> conditions = new ArrayList<String>();
        if (ssgsId != null) {
            conditions.add(" w.sbgs.id=? ");
            param.add(ssgsId);
        }
        if (StringUtils.isNotEmpty(spzt) && !spzt.equalsIgnoreCase("null")) {
            conditions.add(" w.zt=? ");
            param.add(spzt);
        }
        String hql = null;
        if (forZjjh)
            hql = "select w from Zgwzjh w left join w.zgzjjh z where z.id is null " + (conditions.isEmpty() ? "" : " and " + StringUtils.join(conditions, "and ")) + "order by w.dateCreated desc";
        else
            hql = "from Zgwzjh w " + (conditions.isEmpty() ? "" : " where " + StringUtils.join(conditions, "and ")) + "order by w.dateCreated desc";
        return find(page, hql, param.toArray());
    }
}
